/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DetectarLineas;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.SampleModel;
import java.lang.Object;
import java.awt.Color;


/**
 *
 * @author practica
 */

//Filtro para realizar el paso 1 del BSD
public class Paso1 {

    public BufferedImage aplica_paso1(BufferedImage imag){
        int width = imag.getWidth();
        int height = imag.getHeight();
        BufferedImage ejemplo = new BufferedImage(width,height, imag.getType());
        for(int i=0;i<width;i++){
            for(int j=0; j<height;j++){
                ejemplo.setRGB(i, j, media(i, j,imag));
            }
        }
        return ejemplo;
    }

    public int media(int i, int j, BufferedImage imag){
        int pix = 0;
        int rojo = 0;
        int azul = 0;
        int verde = 0;
        int cont=0;

        for(int aux1=j-5; aux1<=j+5; aux1++){
            if(aux1>=0 && aux1<imag.getHeight()){
                pix = imag.getRGB(i,aux1);
                cont++;
                rojo = rojo + ((pix & 0x00ff0000) >> 16);
                verde = verde + ((pix & 0x0000ff00) >> 8);
                azul = azul +((pix & 0x000000ff)>> 0);
 
           }
        }

        Color c=null;
        if(cont!=0)
            c = new Color(rojo/cont,verde/cont,azul/cont);
        else
            c = new Color(0,0,0);

       return c.getRGB();
       
    }


}
